#!/usr/bin/env python
'''
This program is used to plot data from the file.
Special for my Phys 102 students.

To get help use it with parameter -h
'''

__author__ = "Vladimir Iglovikov"

import argparse
import sys
import matplotlib.pyplot as plt

parser = argparse.ArgumentParser()

parser.add_argument('-i', default = 'temp', type=str, help="Input file name")
parser.add_argument('-xlabel', type=str, help="Your x axis label")
parser.add_argument('-ylabel', type=str, help="Your y axis label")
parser.add_argument('-i_x', type=str, help="xInput file")
parser.add_argument('-i_y', type=str, help="yInput file")

args = vars(parser.parse_args(sys.argv[1:]))

if args['i'] != 'temp':

  input_file = open(args['i'])

  xList = []
  yList = []

  for line in input_file.readlines():
    tempLine = line.strip().split()
    x = float(tempLine[0])
    y = float(tempLine[1])

    xList += [x]
    yList += [y]
else:
  input_file_x = open(args['i_x'])
  input_file_y = open(args['i_y'])

  xList = []
  yList = []

  for line in input_file_x.readlines():
    tempLine = line.strip().split()
    x = float(tempLine[0])
    xList += [x]
    

  for line in input_file_y.readlines():
    tempLine = line.strip().split()
    
    y = float(tempLine[0])
    
    yList += [y]

plt.xlabel(args['xlabel'])
plt.ylabel(args['ylabel'])
plt.grid()
plt.plot(xList, yList, 'o-')
plt.show()
